<template>
  <nav class="shell" :class="{ close: isShellClosed }">
    <header>
      <div class="image-text">
        <span class="image">
          <!-- <img src="./1.jpg" alt="" /> -->
        </span>
        <div class="text logo-text">
          <span class="name">山羊の前端小窝</span>
          <span class="software">-bilibili-</span>
        </div>
      </div>
      <i class="iconfont icon-xiangyoujiantou toggle" @click="toggleShell"></i>
    </header>
    <div class="menu-bar">
      <div class="menu">
        <li class="search-box">
          <i class="iconfont icon-sousuo icon"></i>
          <input type="text" placeholder="搜索..." />
        </li>
        <ul class="menu-links">
          <li class="nav-link" v-for="item in navLinks" :key="item.name">
            <a href="#">
              <i :class="['iconfont', item.iconClass, 'icon']"></i>
              <span class="text nac-text">{{ item.name }}</span>
            </a>
          </li>
        </ul>
      </div>
      <div class="bottom-content">
        <li>
          <a href="#">
            <i class="iconfont icon-zhuxiaoyuan icon"></i>
            <span class="text nac-text">注销</span>
          </a>
        </li>
        <li class="mode">
          <div class="sun-moon">
            <i class="iconfont icon-rijian icon sun"></i>
            <i class="iconfont icon-yejian icon moon"></i>
          </div>
          <span class="mode-text text">{{ modeText }}</span>
          <div class="toggle-switch" @click="toggleMode">
            <span class="switch"></span>
          </div>
        </li>
      </div>
    </div>
  </nav>
</template>

<script>
export default {
  name: 'SideBar',
  data() {
    return {
      isShellClosed: true,
      isDarkMode: false,
      modeText: '夜间模式',
      navLinks: [
        { name: '主页', iconClass: 'icon-shouye' },
        { name: '我的收藏', iconClass: 'icon-shoucangxiao' },
        { name: '历史记录', iconClass: 'icon-lishi' },
        { name: '消息', iconClass: 'icon-xiaoxi' },
        { name: '粉丝管理', iconClass: 'icon-fensi' },
        { name: '创作中心', iconClass: 'icon-chuangzuo' },
      ],
    };
  },
  methods: {
    toggleShell() {
      this.isShellClosed = !this.isShellClosed;
    },
    toggleMode() {
      this.isDarkMode = !this.isDarkMode;
      this.modeText = this.isDarkMode ? '白日模式' : '夜间模式';
      document.body.classList.toggle('dark', this.isDarkMode);
    },
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background-color: var(--body-color);
  transition: all 0.3s ease;
}

/* 设置全局变量 */
:root {
  --body-color: #e4e9f7;
  --shell-color: #fff;
  --primary-color: #695cfe;
  --primary-color-light: #f6f5ff;
  --toggle-color: #ddd;
  --text-color: #707070;
}

/* 深色主题变量 */
.dark {
  --body-color: #202224;
  --shell-color: #171717;
  --primary-color: #3a3b3c;
  --primary-color-light: #3a3b3c;
  --toggle-color: #fff;
  --text-color: #ccc;
}

.shell {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 250px;
  padding: 10px 14px;
  background: var(--shell-color);
  transition: all 0.3s ease;
  z-index: 100;
}

.shell.close {
  width: 0;
}

.shell .toggle {
  position: absolute;
  top: 50%;
  right: -25px;
  transform: translateY(-50%) rotate(180deg);
  height: 25px;
  width: 25px;
  background-color: var(--primary-color);
  color: var(--shell-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.menu-bar {
  height: calc(100% - 55px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: scroll;
}

.menu-bar::-webkit-scrollbar {
  display: none;
}

.mode .sun-moon i.sun {
  opacity: 0;
}

.dark .shell li a:hover .icon,
.dark .shell li a:hover .text {
  color: #ccc;
}

.dark .mode .sun-moon i.sun {
  opacity: 1;
}
</style>
